<template>
  <div class="fixed bottom-0 left-0 right-0 pb-safe px-4">
    <wd-button custom-class="w-full" @click="startScan">开始扫描</wd-button>
  </div>
</template>


<script setup lang="ts">
import { jAlert3 } from '@/utils';
onShareAppMessage(() => ({
  title: 'uniapp扫码',
  path: '/pagesA/scanQR/index'
}));


const isScan = ref(false)

const startScan = () => {
  isScan.value = true
  uni.scanCode({
    success: (res) => {
      if (res.result) {
        console.log('扫描结果：', res.result);
        jAlert3(res.result)
      } else {
        uni.showToast({
          title: '扫描失败',
          icon: 'none'
        });
      }
    },
    fail: (err) => {
      if (err.errMsg.includes('cancel')) {
        uni.showToast({
          title: '扫描已取消',
          icon: 'none'
        });
      } else {
        uni.showToast({
          title: '调用相机失败',
          icon: 'none'
        });
      }
    }
  });
}

</script>

<style scoped lang="scss"></style>
